/*
 * BlackLightning.PluginLib.TimerMessage
 * Andy Tidball
 * 
 * Project: Black Lightning Plugin Library
 * Copyright: GNU General Public License
 */

using System;

namespace BlackLightning.PluginLib {
	/// <summary>
	/// A message sent to Black Lightning to deal with a timer.
	/// </summary>
	[Serializable]
	public class TimerMessage : Message {
		// member data
		private int _ID; // the ID of the timer in question

		/// <summary>
		/// Creates a new TimerMessage.
		/// </summary>
		/// <param name="ID">The ID of the timer in question.</param>
		public TimerMessage(int ID) {
			_ID = ID;
		}

		/// <summary>
		/// Gets the ID of the option in question.
		/// </summary>
		public int ID {
			get {
				return _ID;
			}
		}
	}

	/// <summary>
	/// A message sent to Black Lightning to register a timer.
	/// </summary>
	[Serializable]
	public class RegisterTimerMessage : TimerMessage {
		// member data
		private DateTime _Start;    // the time when the timer should first expire
		private int      _Count;    // the number of times that the timer should expire
		private int      _Interval; // the number of milliseconds between consecutive expirations

		/// <summary>
		/// Creates a new timer that fires once at the given time.
		/// </summary>
		/// <param name="ID">An ID that's meaningful (and unique) to the owning module.</param>
		/// <param name="Start">The time that the timer should fire.</param>
		public RegisterTimerMessage(int ID, DateTime Start)
			: this(ID, Start, 1, 0) {
		}

		/// <summary>
		/// Creates a new timer that starts immediately and repeats indefinitely.
		/// </summary>
		/// <param name="ID">An ID that's meaningful (and unique) to the owning module.</param>
		/// <param name="Interval">The number of milliseconds between the timer's repeating expirations.</param>
		public RegisterTimerMessage(int ID, int Interval)
			: this(ID, DateTime.Now, 0, Interval) {
		}

		/// <summary>
		/// Creates a new timer that starts immediately and repeats a given number of times.
		/// </summary>
		/// <param name="ID">An ID that's meaningful (and unique) to the owning module.</param>
		/// <param name="ExpireCount">The number of times that the timer will expire, or 0 to repeat indefinitely.</param>
		/// <param name="Interval">The number of milliseconds between the timer's repeating expirations.</param>
		public RegisterTimerMessage(int ID, int ExpireCount, int Interval)
			: this(ID, DateTime.Now, ExpireCount, Interval) {
		}

		/// <summary>
		/// Creates a new timer that starts at the given time and repeats indefinitely.
		/// </summary>
		/// <param name="ID">An ID that's meaningful (and unique) to the owning module.</param>
		/// <param name="Start">The time that the timer should first expire.</param>
		/// <param name="Interval">The number of milliseconds between the timer's repeating expirations.</param>
		public RegisterTimerMessage(int ID, DateTime Start, int Interval)
			: this(ID, Start, 0, Interval) {
		}

		/// <summary>
		/// Creates a new timer that starts at the given time and repeats a given number of times.
		/// </summary>
		/// <param name="ID">An ID that's meaningful (and unique) to the owning module.</param>
		/// <param name="Start">The time that the timer should first expire.</param>
		/// <param name="ExpireCount">The number of times that the timer will expire, or 0 to repeat indefinitely.</param>
		/// <param name="Interval">The number of milliseconds between the timer's repeating expirations.</param>
		public RegisterTimerMessage(int ID, DateTime Start, int ExpireCount, int Interval)
			: base(ID) {
			_Start    = Start;
			_Count    = ExpireCount;
			_Interval = Interval;
		}

		/// <summary>
		/// Gets the date and time that the timer should initially expire.
		/// </summary>
		public DateTime Start {
			get {
				return _Start;
			}
		}

		/// <summary>
		/// Gets the number of milliseconds between recurring expirations of the timer, once the timer's Start time has passed.
		/// </summary>
		public int Interval {
			get {
				return _Interval;
			}
		}

		/// <summary>
		/// Gets the number of times that this timer should expire.
		/// </summary>
		public int ExpireCount {
			get {
				return _Count;
			}
		}
	}

	/// <summary>
	/// A message sent to Black Lightning to unregister a timer.
	/// </summary>
	[Serializable]
	public class UnregisterTimerMessage : TimerMessage {
		/// <summary>
		/// Creates a new UnregisterTimerMessage.
		/// </summary>
		/// <param name="ID">The ID of the timer to unregister.</param>
		public UnregisterTimerMessage(int ID)
			: base(ID) {
		}
	}

	/// <summary>
	/// A message sent to a Module when one of its registered timers expires.
	/// </summary>
	[Serializable]
	public class TimerExpiredMessage : TimerMessage {
		/// <summary>
		/// Creates a new TimerExpiredMessage.
		/// </summary>
		/// <param name="ID">The ID of the timer that expired.</param>
		public TimerExpiredMessage(int ID)
			: base(ID) {
		}
	}
}
